package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.EmailTemplate;
import com.oocl.euc.core.maintenance.repository.EmailTemplateRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class EmailTemplateBuilder {

    public static final String EMAIL_TEMPALTE_KEY = "test";
    public static final String ERROR_EMAIL_TEMPALTE_KEY = "erroTest";
    public static final String SEND_FROM = "wune";
    public static final String SEND_TO = "zhousk";
    private EmailTemplate emailTemplate;

    @Autowired
    EmailTemplateRepository emailTemplateRepository;

    public EmailTemplateBuilder defaultBuilder(){
        emailTemplate = new EmailTemplate();
        emailTemplate.setEmailTempalteKey(EMAIL_TEMPALTE_KEY);
        emailTemplate.setSendFrom(SEND_FROM);
        emailTemplate.setSendTo(SEND_TO);
        return this;
    }

    public EmailTemplate create() {
        return emailTemplate;
    }

    public EmailTemplate saveToDB(){
        EmailTemplate save = emailTemplateRepository.save(emailTemplate);
        return save;
    }

    public EmailTemplateBuilder withKey(String key){
        emailTemplate.setEmailTempalteKey(key);
        return this;
    }

    public EmailTemplateBuilder withFrom(String from){
        emailTemplate.setSendFrom(from);
        return this;
    }

    public EmailTemplateBuilder withTo(String to){
        emailTemplate.setSendTo(to);
        return this;
    }

    public EmailTemplateBuilder withCC(String cc){
        emailTemplate.setEmailCC(cc);
        return this;
    }

    public EmailTemplateBuilder withBCC(String bcc){
        emailTemplate.setEmailBCC(bcc);
        return this;
    }

    public EmailTemplateBuilder withSuject(String subject){
        emailTemplate.setSubject(subject);
        return this;
    }

    public EmailTemplateBuilder withContent(String content){
        emailTemplate.setContent(content);
        return this;
    }

}
